package moocloudstudio.minder.enums;

import cn.hutool.core.util.StrUtil;
import lombok.Getter;

@Getter
public enum BooleanEnum {
    True("1"),
    False("0");

    private final String value;

    BooleanEnum(String value){
        this.value = value;
    }

    public static BooleanEnum toEnum(String value){
        if (StrUtil.isBlank(value)){
            throw new IllegalArgumentException("参数不能为空");
        }
        return switch (value){
            case "0" -> BooleanEnum.False;
            case "1" -> BooleanEnum.True;
            default -> throw new IllegalArgumentException("非法的参数");
        };
    }

    /**
     * 取反
     * @param value 逻辑值
     * @return 取反后的值
     */
    public static String not(String value){
        return switch (value){
            case "0" -> BooleanEnum.True.getValue();
            case "1" -> BooleanEnum.False.getValue();
            default -> throw new IllegalArgumentException("非法的参数");
        };
    }
}
